package io.jt808.proto.req;

import io.norland.buffer.AutoBuffer;
import io.norland.annotations.Proto;
import io.norland.proto.IProto;
import lombok.Data;

/**
 * 车辆控制应答
 */
@Proto("0500")
@Data
public class JT0500 implements IProto {
    /**
     * 应答流水号
     */
    private int responseMessageSerialNo;
    /**
     * 位置信息汇报消息体,根据对应的状态位判断控制成功与否
     */
    private JT0200 positionReport;

    public final byte[] writeToBytes() {
        AutoBuffer buff = new AutoBuffer();
        buff.writeShort(responseMessageSerialNo);
        buff.writeBytes(positionReport.writeToBytes());
        return buff.array();
    }

    public final void readFromBuf(AutoBuffer buffer) {
        responseMessageSerialNo = buffer.readUnsignedShort();
        JT0200 jt0200 = new JT0200();
        jt0200.readFromBuf(buffer);
        positionReport = jt0200;
    }

//    public static void main(String[] args) {
//        String hex = "000000000000000301595e3206bcfd58000002940000181024141936010400011abb";
//        byte[] bytes = Tools.HexString2Bytes(hex);
//        byte[] bytes1 = new byte[bytes.length + 2];
//        bytes1[0] = 0x33;
//        bytes1[1] = 0x34;
//        System.arraycopy(bytes, 0, bytes1, 2, bytes.length);
//        AutoBuffer buffer = new AutoBuffer(bytes1);
//        JT0500 jt0200 = new JT0500();
//        jt0200.readFromBuf(buffer);
//        System.out.println(new String(bytes1).equals(new String(jt0200.writeToBytes())));
//    }
}